package org.wang.portal.core;

import org.wang.portal.task.TaskOrchestrator;

import java.util.List;

public class OrchestrateOperationStrategy implements OperationStrategy {
    @Override
    public void execute(String[] args) {
        if (args.length < 3) {
            System.out.println("Usage: Main orchestrate <add/update/delete/list> <templateName> [taskTypes]");
            System.exit(1);
        }
        TaskOrchestrator taskOrchestrator = new TaskOrchestrator();
        String action = args[1];
        String templateName = args[2];
        switch (action) {
            case "add":
            case "update":
                if (args.length < 4) {
                    System.out.println("Usage: Main orchestrate " + action + " <templateName> <taskTypes>");
                    System.exit(1);
                }
                List<String> taskTypeList = List.of(args[3].split(","));
                if ("add".equalsIgnoreCase(action)) {
                    taskOrchestrator.addCustomTemplate(templateName, taskTypeList);
                } else {
                    taskOrchestrator.updateCustomTemplate(templateName, taskTypeList);
                }
                break;
            case "delete":
                taskOrchestrator.deleteCustomTemplate(templateName);
                break;
            case "list":
                taskOrchestrator.getTemplateList();
                break;
            default:
                System.out.println("Invalid action: " + action);
                System.exit(1);
        }
    }
}